package com.rpframework.website.device.act.admin;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.rpframework.utils.NumberUtils;
import com.rpframework.utils.Pager;
import com.rpframework.website.device.service.OpinionService;

@Controller
@RequestMapping("/admin/opinion")
public class AdminOpinipnAct extends AdminAct{
	@Resource OpinionService service;
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	@RequestMapping("/list")
	public String list(@RequestParam(value="pager", required=false) Pager pager, 
			@RequestParam(value="state", required=false) Integer state, 
			Map<Object, Object> model){
		if(pager == null) {
			pager = new Pager();
		}
		if(NumberUtils.isValid(state)){
			pager.getSearchMap().put("state", state.toString());
			model.put("state", state);
		}
		pager = service.getpager(pager);
		model.put("pager", pager);
		return this.doPackageURI("opinion/list");
	}
	@RequestMapping("/delete-{id}")
	public String delete(@PathVariable Integer id ,RedirectAttributes attr){
		boolean flag = service.delete(id);
		if(flag){
			setInfoMsg("删除成功！", attr);
		}else{
			setInfoMsg("删除失败！", attr);
		}
		return redirect("/admin/opinion/list");
	}
}
